/**
 * @File   : ajax.js
 * @Author : xue.xiaoBing
 * @Date   : 2020/11/4
 * @Desc   : 提供get, post, put, patch, delete请求
 **/

import axios from 'axios'


export default function ajax(url, data, method = 'GET') {

  if (method === "GET") {
    return axios({
      method: 'GET',
      url: url,
      data: data,
      headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}

    })
  } else if (method === "POST") {
    let formData = new FormData();
    for (const key in data) {
      formData.append(key, data[key])
    }
    return axios({
      method: 'POST',
      url: url,
      data: formData,
    })
  } else if (method === "PUT") {
    return axios.put(url, data)
  } else if (method === "PATCH") {

  } else if (method === "DELETE") {

  }
}